<template>
  <div class="relative w-full h-full">
    <SearchCom :searchList="searchConfig" @search="handleSearch" />
    <el-table
      :data="tableData"
      style="width: 100%"
      class="cover-table mt12"
      border
    >
      <el-table-column label="序号" width="80">
        <template #default="scope">
          <span>{{ scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="username" label="账号" />
      <el-table-column prop="powerGroup" label="所属权限组" />
      <el-table-column prop="phone" label="电话" />
      <el-table-column prop="createTime" label="创建时间" />
      <el-table-column prop="status" label="状态">
        <template #default="scope">
          <span>{{ scope.row.status === 1 ? "启用" : "冻结" }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template #default="scope">
          <div class="flex_aic_jcc">
            <div class="operationBtn">
              <el-button type="text" size="small" @click="handleEdit(scope.row)"
                >编辑</el-button
              >
            </div>
            <div class="operationBtn">
              <el-button
                type="text"
                size="small"
                @click="handleStatus(scope.row)"
                >{{ scope.row.status === 1 ? "冻结" : "启用" }}</el-button
              >
            </div>
            <div class="operationBtn">
              <el-button
                type="text"
                size="small"
                @click="handleResetPassword(scope.row)"
                >重置密码</el-button
              >
            </div>
            <el-popconfirm
              title="确定删除吗？"
              @confirm="handleDelete(scope.row)"
              confirm-button-text="确定"
              cancel-button-text="取消"
            >
              <template #reference>
                <el-button class="ml0" type="text" size="small">删除</el-button>
              </template>
            </el-popconfirm>
          </div>
        </template>
      </el-table-column>
    </el-table>

    <div class="flex justify-end mt24">
      <el-pagination
        v-model:current-page="currentPage"
        v-model:page-size="pageSize"
        :page-sizes="[10, 20, 30, 40]"
        layout="total, sizes, prev, pager, next, jumper"
        :total="400"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>
    <EditDia v-model="editDiaVisible" :data="editDiaData"></EditDia>
    <ResetPswDia v-model="resetPswDiaVisible"></ResetPswDia>
  </div>
</template>

<script setup>
import { ref } from "vue";
import EditDia from "./editDia.vue";
import ResetPswDia from "./resetPswDia.vue";
import SearchCom from "@/components/SearchCom.vue";

const searchConfig = ref([
  {
    label: "账号名称",
    prop: "username",
    type: "input",
  },
]);

const editDiaVisible = ref(false);
const editDiaData = ref({});
const resetPswDiaVisible = ref(false);
const currentPage = ref(1);
const pageSize = ref(10);
const tableData = ref(
  Array(10).fill({
    username: "张三",
    powerGroup: "权限组1",
    phone: "12345678901",
    createTime: "2021-01-01 12:00:00",
    status: 1,
  })
);
const handleDelete = (row) => {
  console.log(row);
};
const handleEdit = (row) => {
  editDiaVisible.value = true;
  editDiaData.value = row;
};
const handleSizeChange = (size) => {
  pageSize.value = size;
};
const handleCurrentChange = (page) => {
  currentPage.value = page;
};
const handleStatus = (row) => {
  row.status = row.status === 1 ? 0 : 1;
};
const handleResetPassword = (row) => {
  console.log(row);
  resetPswDiaVisible.value = true;
};
</script>

<style lang="scss" scoped>
.addBtn {
  height: 28px;
  margin-left: 10px;
  padding: 0 7px;
  border-radius: 3px;
  background: #fff;
  cursor: pointer;
}
.split {
  width: 1px;
  height: 12px;
  background: #ddd;
  margin: 0 5px;
}
</style>
